package com.lagou.edu.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.alibaba.druid.util.StringUtils;

public class ConfigurationUtils {

    public Properties properties;

    public ConfigurationUtils(String propertiesPath) {
        properties = this.getBeanScanPath(propertiesPath);
    }

    public ConfigurationUtils() {
        this(null);
    }

    private Properties getBeanScanPath(String propertiesPath) {
        if(StringUtils.isEmpty(propertiesPath)){
            propertiesPath = "/application.properties";
        }

        Properties properties = new Properties();
        try (InputStream is = ConfigurationUtils.class.getResourceAsStream(propertiesPath)){
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

    public String getPropertiesByKey(String key){
        return properties.getProperty(key);
    }
}
